// 深度优先遍历  // 遍历的基础上添加索引
function leavelOrder(root) {
    let result = [], index = 0;
    const level = (root, index) => {
        if (!root) return
        if(!result[index]) result[index] =[];
        result[index].push(root.val)
        root.children.forEach(child => level(child, index+1))
    }
    level(root, index)
    return result
}